package com.hcy.performancepro.service.performanceTool.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuled.test.tool_config.DisableUtil;
import com.hcy.performancepro.bo.performanceTool.RecordDaoBo;
import com.hcy.performancepro.dao.performanceTool.PerformanceToolDaoDao;
import com.hcy.performancepro.po.performanceTool.RecordDao;
import com.hcy.performancepro.service.performanceTool.PerformanceToolDaoService;
import org.springframework.stereotype.Service;
import java.util.List;

@Service("PerformanceToolDaoServiceImpl")
@DisableUtil
public class PerformanceToolDaoServiceImpl extends ServiceImpl<PerformanceToolDaoDao, RecordDao> implements PerformanceToolDaoService {

    public Wrapper<RecordDao> getWrapper(RecordDaoBo recordDaoBo) {
        LambdaQueryWrapper<RecordDao> wrapper = Wrappers.lambdaQuery();
        wrapper.like(StrUtil.isNotBlank(recordDaoBo.getLevel()), RecordDao::getLevel, recordDaoBo.getLevel());
        wrapper.like(StrUtil.isNotBlank(recordDaoBo.getRequestId()), RecordDao::getRequestId, recordDaoBo.getRequestId());
        wrapper.like(StrUtil.isNotBlank(recordDaoBo.getFunctionName()), RecordDao::getFunctionName, recordDaoBo.getFunctionName());
        wrapper.like(StrUtil.isNotBlank(recordDaoBo.getModuleName()), RecordDao::getModuleName, recordDaoBo.getModuleName());
        wrapper.like(StrUtil.isNotBlank(recordDaoBo.getCostTime()), RecordDao::getCostTime, recordDaoBo.getCostTime());
        wrapper.like(StrUtil.isNotBlank(recordDaoBo.getTimestamp()), RecordDao::getTimestamp, recordDaoBo.getTimestamp());
        wrapper.like(StrUtil.isNotBlank(recordDaoBo.getParams()), RecordDao::getParams, recordDaoBo.getParams());
        wrapper.like(StrUtil.isNotBlank(recordDaoBo.getReturnMessage()), RecordDao::getReturnMessage, recordDaoBo.getReturnMessage());
        wrapper.like(StrUtil.isNotBlank(recordDaoBo.getExceptionMessage()), RecordDao::getExceptionMessage, recordDaoBo.getExceptionMessage());
        return wrapper;
    }

    @Override
    public List<RecordDao> sarchlist(Integer currentPage, Integer pageSize, RecordDaoBo recordDaoBo) {
        return baseMapper.selectList(new Page<>(currentPage, pageSize), getWrapper(recordDaoBo));
    }

    @Override
    public Long countNumber(RecordDaoBo recordDaoBo) {
        return baseMapper.selectCount(getWrapper(recordDaoBo));
    }

}
